// WndVolume.cpp : implementation file
//

#include "stdafx.h"
#include "BBViewer.h"
#include "WndVolume.h"

#include "../_inc_util/UtilSound.h"

// CWndVolume

IMPLEMENT_DYNAMIC(CWndVolume, CWnd)

CWndVolume::CWndVolume()
{
}

CWndVolume::~CWndVolume()
{
}


BEGIN_MESSAGE_MAP(CWndVolume, CWnd)
	ON_WM_CREATE()
	ON_WM_PAINT()
	ON_WM_SIZE()
	ON_MESSAGE(WM_CTL_MESSAGE, OnCtlMessage)
END_MESSAGE_MAP()



// CWndVolume message handlers


int CWndVolume::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	LPST_BMP_INFO lpBmpInfo1, lpBmpInfo2;
	lpBmpInfo1 = theApp.BmpInfo.GetAt(biVol_slider);
	lpBmpInfo2 = theApp.BmpInfo.GetAt(biVol_thumb);
	m_slrVolume.SetBitmaps(lpBmpInfo1->hbmpImage, lpBmpInfo2->hbmpImage, TRUE);

	LPST_BMP_INFO lpBmpInfo;
	lpBmpInfo = theApp.BmpInfo.GetAt(biVol_bk);
	if (!m_slrVolume.Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0, 0, 0, 0), this, lpBmpInfo->uImageID, NULL))			
		return  -1;		

	DWORD  dwVolume = 30;
	CUtilSound utilSound;

	if (utilSound.InitMasterVolume())
	{
		dwVolume = utilSound.GetMasterVolume()/1092;

		if (dwVolume > 60)
			dwVolume = 60;
	}

	int nBackSize, nThumbSize;
	lpBmpInfo = theApp.BmpInfo.GetAt(biVol_slider);
	nBackSize = lpBmpInfo->rtImageRect.Width();
	lpBmpInfo = theApp.BmpInfo.GetAt(biVol_thumb);
	nThumbSize = lpBmpInfo->rtImageRect.Width();
	m_slrVolume.SetSize(nBackSize, nThumbSize);
	m_slrVolume.SetRange(0, 60);	
	m_slrVolume.SetPos(dwVolume);

	return 0;
}

void CWndVolume::OnPaint()
{
	CPaintDC dc(this);

	CDC dcMemory;
	CBitmap *pBmp;
	LPST_BMP_INFO lpBmpInfo = theApp.BmpInfo.GetAt(biVol_bk);
	dcMemory.CreateCompatibleDC(&dc);
	pBmp = CBitmap::FromHandle(lpBmpInfo->hbmpImage);
	CBitmap* pBmpOld = dcMemory.SelectObject(pBmp);

	LPST_WND_POS lpWndPos = theApp.WndPos.GetAt(wpVolume);
	dc.BitBlt(0, 0, lpBmpInfo->rtImageRect.Width(), lpBmpInfo->rtImageRect.Height(), &dcMemory, 0, 0, SRCCOPY);
	dcMemory.SelectObject(pBmpOld);
	dcMemory.DeleteDC();		//2013.04.29


}

void CWndVolume::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	LPST_WND_POS lpWndPos = theApp.WndPos.GetAt(wpVolumeSlider);
	theApp.SetWindowPosition(&m_slrVolume, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
}

long CWndVolume::OnCtlMessage(UINT wParam, LONG lParam)
{
	CWnd* pParent = GetParent();

	pParent->PostMessage(WM_PLB_MESSAGE, wParam, lParam);
	return 0;
}